<script setup lang="ts">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'

const { required, lengthRange } = useValidator()

const formSchema = reactive<FormSchema[]>([
  {
    field: 'product_type',
    label: '机型',
    component: 'Input'
  },
  {
    field: 'flight',
    label: '架次',
    component: 'Input'
  },
  {
    field: 'station',
    label: '工位',
    component: 'Input'
  },
  {
    field: 'position',
    label: '站位',
    component: 'Input'
  }
])

const rules = reactive({
  name: [required(), lengthRange({ max: 20 })],
  type: [lengthRange({ max: 20 })],
  number: [lengthRange({ max: 20 })],
  unit: [lengthRange({ max: 20 })]
})

const { formRegister, formMethods } = useForm()
const { setValues, getFormData, getElFormExpose } = formMethods

const submit = async () => {
  const elForm = await getElFormExpose()
  const valid = await elForm?.validate().catch((err) => {
    console.log(err)
  })
  if (valid) {
    const formData = await getFormData()
    return formData
  }
}

defineExpose({
  submit
})
</script>

<template>
  <div>
    <ol class="mb-8">
      <li style="margin-top: 7px">以工单组件为基础，同步任务列表</li>
      <li style="margin-top: 7px">从计划、物流组件补充任务信息</li>
      <li style="margin-top: 7px">未填参数，则全量同步</li>
      <li style="margin-top: 7px">全量同步较慢，可关闭对话框在后台运行</li>
    </ol>
    <Form :rules="rules" @register="formRegister" :schema="formSchema" :isCol="false" />
  </div>
</template>
